<?php if (!defined('THINK_PATH')) exit();?><!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>怡臣 | 店铺管理</title>
    <!-- Tell the browser to be responsive to screen width -->
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
    <!-- Bootstrap 3.3.6 -->
    <link rel="stylesheet" href="/Public/admin/adminlte/bootstrap/css/bootstrap.min.css">
    <!-- Font Awesome -->
    <link rel="stylesheet" href="/Public/admin/adminlte/plugins/font-awesome/font-awesome.min.css">
    <!-- Ionicons -->
    <!--link rel="stylesheet" href="/Public/admin/adminlte/plugins/ionicons/ionicons.min.css"-->
    <!-- Theme style -->
    <link rel="stylesheet" href="/Public/admin/adminlte/dist/css/AdminLTE.min.css">
    <!-- AdminLTE Skins. Choose a skin from the css/skins
         folder instead of downloading all of them to reduce the load. -->
    <link rel="stylesheet" href="/Public/admin/adminlte/dist/css/skins/_all-skins.min.css">
    <!-- iCheck -->
    <link rel="stylesheet" href="/Public/admin/adminlte/plugins/iCheck/flat/blue.css">
    <!-- Morris chart -->
    <link rel="stylesheet" href="/Public/admin/adminlte/plugins/morris/morris.css">
    <!-- jvectormap -->
    <link rel="stylesheet" href="/Public/admin/adminlte/plugins/jvectormap/jquery-jvectormap-1.2.2.css">
    <!-- Date Picker -->
    <link rel="stylesheet" href="/Public/admin/adminlte/plugins/datepicker/datepicker3.css">
    <!-- Daterange picker -->
    <link rel="stylesheet" href="/Public/admin/adminlte/plugins/daterangepicker/daterangepicker.css">
    <!-- bootstrap wysihtml5 - text editor -->
    <link rel="stylesheet" href="/Public/admin/adminlte/plugins/bootstrap-wysihtml5/bootstrap3-wysihtml5.min.css">
    <link rel="stylesheet" href="/Public/admin/css/common.css">
    <!-- jQuery 2.2.3 -->
    <script src="/Public/admin/adminlte/plugins/jQuery/jquery-2.2.3.min.js"></script>
    <script src="/Public/admin/js/jquery.validate.min.js"></script>
    <script src="/Public/admin/js/jquery.validate.config.js"></script>
    <script src="/Public/admin/js/common.js?v=20170331001"></script>
    <script src="/Public/layer/layer.js"></script>
    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
    <script src="/Public/admin/adminlte/plugins/html5shiv/html5shiv.min.js"></script>
    <script src="/Public/admin/adminlte/plugins/html5shiv/respond.min.js"></script>
    <![endif]-->
</head>
<body class="hold-transition skin-blue sidebar-mini">
<div class="row">
    <div class="col-xs-12">
        <div class="box">
            <div class="box-header">
                <h3 class="box-title"><?php echo ($local_name); ?></h3>
                <div class="form-inline pull-right">
                    <form action="<?php echo U('Special/getProducts',array('local_id'=>$local_id,'order_field'=>'product_id','order'=>$order), '');?>"
                          method="get" pjax-container="">
                        <fieldset>
                            <select class="form-control" name="search_field" style="height: 30px; font-size: 12px;">
                                <option value="name"
                                <?php if($search_field == 'name'): ?>selected="selected"<?php endif; ?>
                                >货品名称</option>
                                <option value="barcode"
                                <?php if($search_field == 'barcode'): ?>selected="selected"<?php endif; ?>
                                >条码</option>
                                <option value="bn"
                                <?php if($search_field == 'bn'): ?>selected="selected"<?php endif; ?>
                                >BN</option>
                            </select>
                            <div class="input-group input-group-sm">
                                <div class="input-group input-group-sm">
                                    <input type="text" class="form-control" placeholder="" name="search"
                                           value="<?php echo ($search); ?>">
                                </div>
                            </div>

                            <div class="input-group input-group-sm">
                                <div class="input-group-btn">
                                    <button type="submit" class="btn btn-primary"><i class="fa fa-search"></i>
                                    </button>
                                </div>
                            </div>
                        </fieldset>
                    </form>
                </div>

            </div>
            <!-- /.box-header -->
            <div class="box-body table-responsive no-padding">
                <table class="table table-hover">
                    <tbody>
                    <tr>
                        <th><input type="checkbox" class="grid-select-all"></th>
                        <th>货品ID<a class="fa fa-fw fa-sort"
                                   href="<?php echo U('Special/getProducts',array('p'=>$p,'order_field'=>'product_id','order'=>$order), '');?>"></a>
                        </th>
                        <th>商品ID<a class="fa fa-fw fa-sort"
                                   href="<?php echo U('Special/getProducts',array('p'=>$p,'order_field'=>'goods_id','order'=>$order), '');?>"></a>
                        </th>
                        <th>名称</th>
                        <th>商品分类</th>
                        <th>图片</th>
                        <th>条码<a class="fa fa-fw fa-sort"
                                 href="<?php echo U('Special/getProducts',array('p'=>$p,'order_field'=>'barcode','order'=>$order), '');?>"></a>
                        </th>
                        <th>BN<a class="fa fa-fw fa-sort"
                                 href="<?php echo U('Special/getProducts',array('p'=>$p,'order_field'=>'bn','order'=>$order), '');?>"></a>
                        </th>
                        <th>销售价<a class="fa fa-fw fa-sort"
                                  href="<?php echo U('Special/getProducts',array('p'=>$p,'order_field'=>'price','order'=>$order), '');?>"></a></th>
                        <th>市场价<a class="fa fa-fw fa-sort"
                                  href="<?php echo U('Special/getProducts',array('p'=>$p,'order_field'=>'marketprice','order'=>$order), '');?>"></a></th>
                        <th>折后价<a class="fa fa-fw fa-sort"
                                  href="<?php echo U('Special/getProducts',array('p'=>$p,'order_field'=>'discount','order'=>$order), '');?>"></a></th>
                        <th>库存<a class="fa fa-fw fa-sort"
                                 href="<?php echo U('Special/getProducts',array('p'=>$p,'order_field'=>'store','order'=>$order), '');?>"></a></th>
                    </tr>
                    <?php if(is_array($list)): $i = 0; $__LIST__ = $list;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$vo): $mod = ($i % 2 );++$i;?><tr class="cg-product-tr">
                            <td><input type="checkbox" class="grid-item" data-id="<?php echo ($vo["store_pid"]); ?>" <?php if($vo['is_show'] == true): ?>checked<?php endif; ?> ></td>
                            <td><?php echo ($vo["product_id"]); ?></td>
                            <td><?php echo ($vo["goods_id"]); ?></td>
                            <td><?php echo ($vo["name"]); ?></td>
                            <td><?php echo ($vo["cat_name"]); ?></td>
                            <td><img src="<?php echo (getthumb($vo["goods_id"])); ?>" data-bimg="<?php echo (getthumb($vo["goods_id"])); ?>" alt="" class="scale-img"></td>
                            <td><?php echo ($vo["barcode"]); ?></td>
                            <td><?php echo ($vo["bn"]); ?></td>
                            <td><?php echo ($vo["price"]); ?></td>
                            <td><?php echo ($vo["marketprice"]); ?></td>
                            <td><?php echo ($vo["discount"]); ?></td>
                            <td><?php echo ($vo["store"]); ?></td>
                        </tr><?php endforeach; endif; else: echo "" ;endif; ?>
                    </tbody>
                </table>
            </div>
            <div class="box-footer clearfix">
                <input type="checkbox" class="grid-select-all">&nbsp;&nbsp;&nbsp;
                <a class="btn btn-sm btn-info batch-choose">保存</a>
                <a class="btn btn-sm btn-primary grid-refresh"><i class="fa fa-refresh"></i></a>
                <?php echo ($page); ?>
            </div>
            <!-- /.box-body -->
        </div>
    </div>
</div>
<script type="text/javascript">
    $(function () {
		var chids = parent.$("#yc-goods-ids").val();
        var ychser = new YcChoser();
        ychser.setChosenIds(chids);
		$(".grid-item").each(function(){
            if(ychser.isRepeat($(this).attr("data-id"))){
                $(this).prop("checked", "checked");
            }
        });
        var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
        $('.grid-select-all').change(function () {
            if (this.checked) {
                $('.grid-item').prop("checked", true);
            } else {
                $('.grid-item').prop("checked", false);
            }
        });
        $('.grid-refresh').click(function () {
            window.location.reload();
        });

        $('.batch-choose').on('click', function (e) {
            if (!confirm("是否继续")) {
                return false;
            }
			$(".grid-item").each(function (i) {
				var store_pid = $(this).attr('data-id');
				var name = $(this).parent().parent().find('td:eq(3)').text();
				var store = $(this).parent().parent().find('td:eq(11)').text();
				var price = $(this).parent().parent().find('td:eq(8)').text();
				var flag = ychser.isRepeat($(this).attr("data-id"));
                if(flag && !$(this).is(':checked')){
                    ychser.remove();
                    parent.$('.ui-sortable').children("li").eq(ychser.getPosition()).remove();
                }else if ($(this).is(':checked') && !flag) {
                    ychser.add($(this).attr("data-id"));
					var html = '';
					html += '<li>';
					html += '<input type="hidden" name="store_pid[]" value="'+store_pid+'">';
					html += '<a href="javascript:;" class="text ebatch-name" title="'+name+'">'+name+'</a>';
					html += '<small class="label label-warning"> 售价 : '+price+'</small>';
					html += '<small class="label label-success"> 库存 : '+store+'</small>';
					html += '<div class="tools">';
					html += '<i class="fa fa-trash-o icondel" data-id="'+store_pid+'" onclick="deleteProduct(this)"></i>';
					html += '</div>';
					html += '</li>';
					parent.$('.ui-sortable').append(html);
					parent.$('.col-sm-offset-2').removeClass('hide');
				}
				parent.updateGoodsIds(ychser.getChosenIds());
            });
            parent.layer.close(index);
        })
		showBigPicture();
    });
</script>
</body>
</html>